import React from 'react';
import {Router} from 'dva/router';
import App from "./routes/App.js";

const cached = {};

function registerModel(app, model) {
    if (!cached[model.namespace]) {
        app.model(model);
        cached[model.namespace] = 1;
    }
}

function RouterConfig({history, app}) {
    const routes = [
        {
            path: '/',
            component: App,
            childRoutes: [
                {
                    path: 'workbench',
                    name: '工作台',
                    breadcrumbName: '工作台',
                    childRoutes: [
                        {
                            path: 'messageCenter',
                            name: '消息中心',
                            breadcrumbName: '消息中心',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/workbench/messageCenter').default)
                                    cb(null, require('./routes/workbench/messageCenter/Index').default);
                                });
                            }
                        },
                        {
                            path: 'userCharts',
                            name: '用户统计图表',
                            breadcrumbName: '用户统计图表',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/workbench/charts').default)
                                    cb(null, require('./routes/workbench/userCharts/Index').default);
                                });
                            }
                        },
                        {
                            path: 'lesseeCharts',
                            name: '平台统计图表',
                            breadcrumbName: 'lesseeCharts',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/workbench/charts').default)
                                    cb(null, require('./routes/workbench/lesseeCharts/Index').default);
                                });
                            }
                        }

                    ]
                },
                {
                    path: 'customer',
                    name: '客户中心',
                    breadcrumbName: '客户中心',
                    childRoutes: [
                        {
                            path: 'customerManage',
                            name: '客户管理',
                            breadcrumbName: '客户管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/customer/businessAgreement').default);
                                    registerModel(app, require('./models/customer/customerManage').default);
                                    registerModel(app, require('./models/auth/lessee').default);
                                    cb(null, require('./routes/customer/customerManage/Index').default);
                                });
                            }
                        },
                        {
                            path: 'customerDetails',
                            name: '客户详情',
                            breadcrumbName: '客户详情',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/customer/statement').default);
                                    registerModel(app, require('./models/customer/businessAgreement').default);
                                    registerModel(app, require('./models/order/orderManage').default);
                                    registerModel(app, require('./models/customer/customerManage').default)
                                    registerModel(app, require('./models/order/orderProduct').default);
                                    registerModel(app, require('./models/order/orderCost').default);
                                    registerModel(app, require('./models/capital/capital').default);
                                    registerModel(app, require('./models/report/customerReport').default);
                                    registerModel(app, require('./models/customer/blacklist').default);
                                    registerModel(app, require('./models/basedata/declaration').default);
                                    registerModel(app, require('./models/outbuy/outbuyProvider').default);
                                    registerModel(app, require('./models/logistics/logisticsSupplier').default)
                                    registerModel(app, require('./models/basedata/customs').default);
                                    registerModel(app, require('./models/settlement/settlement').default);
                                    registerModel(app, require('./models/auth/lesseeAccount').default);
                                    registerModel(app, require('./models/capital/forexPurchase').default);
                                    cb(null, require('./routes/customer/customerDetails/Index').default);
                                });
                            }
                        },
                        {
                            path: 'blacklist',
                            name: '黑名单',
                            breadcrumbName: '黑名单',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/customer/blacklist').default)
                                    cb(null, require('./routes/customer/blacklist/Inddex').default);
                                });
                            }
                        },

                    ]
                },
                {
                    path: 'supplier',
                    name: '供应商中心',
                    breadcrumbName: '供应商中心',
                    childRoutes: [
                        {
                            path: 'outbuyManage',
                            name: '商品供应商',
                            breadcrumbName: '商品供应商',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/outbuy/outbuyProvider').default);
                                    registerModel(app, require('./models/outbuy/outbuyPayer').default);
                                    registerModel(app, require('./models/outbuy/outbuyProduct').default);
                                    cb(null, require('./routes/outbuy/outbuyManage/Index').default);
                                });
                            }
                        },
                        {
                            path: 'logisticsSupplier',
                            name: '物流供应商管理',
                            breadcrumbName: '物流供应商管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/logistics/logisticsSupplier').default)
                                    cb(null, require('./routes/supplier/logisticsSupplier/Index').default);
                                });
                            }
                        },
                    ]
                },
                {
                    path: 'approval',
                    name: '审核中心',
                    breadcrumbName: '审核中心',
                    childRoutes: [
                        {
                            path: 'customerApproval',
                            name: '客户审批',
                            breadcrumbName: '客户审批',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/customer/customerApproval').default)
                                    cb(null, require('./routes/approval/customerApproval/Index').default);
                                });
                            }
                        },
                        {
                            path: 'productApproval',
                            name: '产品审批',
                            breadcrumbName: '产品审批',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/customer/productApproval').default)
                                    cb(null, require('./routes/approval/productApproval/Index').default);
                                });
                            }
                        },
                        {
                            path: 'businessAgreementApproval',
                            name: '业务合同审批',
                            breadcrumbName: '业务合同审批',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/customer/businessAgreement').default)
                                    cb(null, require('./routes/approval/businessAgreementApproval/Index').default);
                                });
                            }
                        },
                        {
                            path: 'outbuyApproval',
                            name: '商品供应商审核',
                            breadcrumbName: '商品供应商审核 ',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/outbuy/outbuyProvider').default)
                                    cb(null, require('./routes/approval/outbuyApproval/Index').default);
                                });
                            }
                        },
                        {
                            path: 'forexPurchaseApproval',
                            name: '购汇审核',
                            breadcrumbName: '购汇审核 ',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/forexPurchase').default);
                                    registerModel(app, require('./models/capital/capital').default);
                                    registerModel(app, require('./models/customer/customerManage').default);
                                    cb(null, require('./routes/approval/forexPurchaseApproval/Index').default);
                                });
                            }
                        },
                    ]
                },
                {
                    path: 'order/',
                    name: '订单中心',
                    breadcrumbName: '订单中心',
                    childRoutes: [
                        {
                            path: 'orderManage',
                            name: '订单管理',
                            breadcrumbName: '订单管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/order/orderManage').default);
                                    registerModel(app, require('./models/order/declareApproval').default);
                                    registerModel(app, require('./models/order/orderProduct').default);
                                    registerModel(app, require('./models/order/orderCost').default);
                                    registerModel(app, require('./models/auth/lessee').default);
                                    registerModel(app, require('./models/basedata/declaration').default);
                                    registerModel(app, require('./models/order/orderProduct').default);
                                    registerModel(app, require('./models/customer/customerManage').default)
                                    registerModel(app, require('./models/logistics/logisticsSupplier').default)
                                    registerModel(app, require('./models/basedata/customs').default);
                                    cb(null, require('./routes/order/orderManage/Index').default);
                                });
                            }
                        },
                        {
                            path: 'declareApproval',
                            name: '通关审批',
                            breadcrumbName: '通关审批',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/order/declareApproval').default);
                                    registerModel(app, require('./models/order/orderCost').default);
                                    registerModel(app, require('./models/order/orderProduct').default);
                                    registerModel(app, require('./models/auth/lessee').default);
                                    registerModel(app, require('./models/basedata/declaration').default);
                                    registerModel(app, require('./models/customer/customerManage').default)
                                    registerModel(app, require('./models/logistics/logisticsSupplier').default)
                                    registerModel(app, require('./models/basedata/customs').default);
                                    cb(null, require('./routes/order/declareApproval/Index').default);
                                });
                            }
                        },
                        // {
                        //     path: 'costApproval',
                        //     name: '费用审批',
                        //     breadcrumbName: '费用审批',
                        //     getComponent(nextState, cb) {
                        //         require.ensure([], (require) => {
                        //             registerModel(app, require('./models/order/orderManage').default);
                        //             registerModel(app, require('./models/customer/customerManage').default)
                        //             cb(null, require('./routes/order/orderManage/Index').default);
                        //         });
                        //     }
                        // }
                    ]
                },
                {
                    path: 'assetsManage',
                    name: '资金管理',
                    breadcrumbName: '资金管理',
                    childRoutes: [
                        {
                            path: 'invoice',
                            name: '开票资料',
                            breadcrumbName: '开票资料',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/order/declareApproval').default);
                                    cb(null, require('./routes/assetsManage/invoice/Index').default);
                                });
                            }
                        },
                        {
                            path: 'approval',
                            name: '付款审核',
                            breadcrumbName: '付款审核',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/capital').default);
                                    registerModel(app, require('./models/order/orderManage').default);
                                    registerModel(app, require('./models/order/orderCost').default);
                                    registerModel(app, require('./models/basedata/declaration').default);
                                    registerModel(app, require('./models/order/orderProduct').default);
                                    cb(null, require('./routes/assetsManage/approval/Index').default);
                                });
                            }
                        },
                        {
                            path: 'pay',
                            name: '客户付款',
                            breadcrumbName: '客户付款',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/capital').default);
                                    cb(null, require('./routes/assetsManage/pay/Index').default);
                                });
                            }
                        },
                        {
                            path: 'forexPurchase',
                            name: '购汇记录',
                            breadcrumbName: '购汇记录',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/forexPurchase').default);
                                    registerModel(app, require('./models/capital/capital').default);
                                    registerModel(app, require('./models/customer/customerManage').default);
                                    registerModel(app, require('./models/outbuy/outbuyProvider').default);
                                    registerModel(app, require('./models/outbuy/outbuyPayer').default);
                                    cb(null, require('./routes/assetsManage/forexPurchase/Index').default);
                                });
                            }
                        },
                        {
                            path: 'claim',
                            name: '外汇关联',
                            breadcrumbName: '外汇关联',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/foreignExchange/claim_t').default);
                                    registerModel(app, require('./models/foreignExchange/foreignExchangeManage_t').default);
                                    cb(null, require('./routes/assetsManage/claim/Index').default)
                                    ;
                                })
                            }
                        },
                        {
                            path: 'revenue',
                            name: '来账认领',
                            breadcrumbName: '来账认领',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/revenue').default);
                                    registerModel(app, require('./models/capital/history').default);
                                    registerModel(app, require('./models/customer/customerManage').default);
                                    registerModel(app, require('./models/auth/lesseeAccount').default);
                                    cb(null, require('./routes/capital/revenue/Index').default);
                                });
                            }
                        },
                        {
                            path: 'aRevenueManage',
                            name: '来账管理',
                            breadcrumbName: '来账管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/revenue').default);
                                    registerModel(app, require('./models/customer/customerManage').default);
                                    registerModel(app, require('./models/capital/history').default);
                                    registerModel(app, require('./models/auth/lesseeAccount').default);
                                    cb(null, require('./routes/capital/revenueManage/Index').default);
                                });
                            }
                        },
                        {
                            path: 'customerFundPool',
                            name: '客户资金池',
                            breadcrumbName: '客户资金池',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/capital/cstFundPool').default);
                                    cb(null, require('./routes/assetsManage/customerFundPool/Index').default);
                                });
                            }
                        },

                    ]
                },
                {
                    path: 'auth',
                    name: '授权中心',
                    breadcrumbName: '授权中心',
                    childRoutes: [
                        {
                            path: 'lessee',
                            name: '租户管理',
                            breadcrumbName: '租户管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/lessee').default);
                                    cb(null, require('./routes/auth/lessee/Index').default);
                                });
                            }
                        },
                        {
                            path: 'organization',
                            name: '组织机构',
                            breadcrumbName: '组织机构',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/organization').default);
                                    cb(null, require('./routes/auth/organization/Index').default);
                                });
                            }
                        },
                        {
                            path: 'user',
                            name: '用户管理',
                            breadcrumbName: '用户管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/user').default);
                                    registerModel(app, require('./models/auth/organization').default);
                                    registerModel(app, require('./models/auth/role').default);
                                    cb(null, require('./routes/auth/user/Index').default);
                                });
                            }
                        },
                        {
                            path: 'role',
                            name: '角色管理',
                            breadcrumbName: '角色管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/app').default);
                                    registerModel(app, require('./models/auth/role').default);
                                    registerModel(app, require('./models/auth/menu').default);
                                    registerModel(app, require('./models/auth/rights').default);
                                    cb(null, require('./routes/auth/role/Index').default);
                                });
                            }
                        },
                        {
                            path: 'menu',
                            name: '菜单管理',
                            breadcrumbName: '菜单管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/app').default);
                                    registerModel(app, require('./models/auth/menu').default);
                                    registerModel(app, require('./models/auth/rights').default);
                                    cb(null, require('./routes/auth/menu/Index').default);
                                });
                            }
                        },
                        {
                            path: 'rights',
                            name: '权限管理',
                            breadcrumbName: '权限管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/app').default);
                                    registerModel(app, require('./models/auth/rights').default);
                                    cb(null, require('./routes/auth/rights/Index').default);
                                });
                            }
                        },
                        {
                            path: 'accountLessee',
                            name: '租户账号管理',
                            breadcrumbName: '租户账号管理',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/auth/lesseeAccount').default);
                                    cb(null, require('./routes/auth/lesessAccount/Index').default);
                                });
                            }
                        },
                    ]
                },
                {
                    path: 'basedata',
                    name: '基础数据',
                    breadcrumbName: '基础数据',
                    childRoutes: [
                        {
                            path: 'exchangeRate',
                            name: '汇率维护',
                            breadcrumbName: '汇率维护',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/exchangeRate').default);
                                    cb(null, require('./routes/basedata/exchangeRate/Index').default);
                                });
                            }
                        },
                        {
                            path: 'customsProductCode',
                            name: '海关商品码维护',
                            breadcrumbName: '海关商品码维护',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/customsProductCode').default);
                                    cb(null, require('./routes/basedata/customsProductCode/Index').default);
                                });
                            }
                        },
                        {
                            path: 'businessParams',
                            name: '业务参数',
                            breadcrumbName: '业务参数',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/businessParams').default);
                                    cb(null, require('./routes/basedata/businessParams/Index').default);
                                });
                            }
                        },
                        {
                            path: 'placeclearance',
                            name: '报关口岸',
                            breadcrumbName: '报关口岸',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/placeclearance').default);
                                    cb(null, require('./routes/basedata/placeclearance/Index').default);
                                });
                            }
                        },
                        {
                            path: 'currency',
                            name: '币种维护',
                            breadcrumbName: '币种维护',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/currency').default);
                                    cb(null, require('./routes/basedata/currency/Index').default);
                                });
                            }
                        },
                        {
                            path: 'strategy',
                            name: '价格策略',
                            breadcrumbName: '价格策略',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/strategy').default);
                                    cb(null, require('./routes/basedata/strategy/Index').default);
                                });
                            }
                        },
                        {
                            path: 'declaration',
                            name: '报关抬头维护',
                            breadcrumbName: '报关抬头维护',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/declaration').default);
                                    cb(null, require('./routes/basedata/declaration/Index').default);
                                });
                            }
                        },
                        {
                            path: 'customs',
                            name: '海关信息',
                            breadcrumbName: '海关信息',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/basedata/customs').default)
                                    cb(null, require('./routes/basedata/customs/Index').default);
                                });
                            }
                        },
                    ]
                },
                {
                    path: 'messagecenter/',
                    name: '消息待办中心',
                    breadcrumbName: '消息待办中心',
                    childRoutes: [
                        {
                            path: 'messageItem',
                            name: '消息中心',
                            breadcrumbName: '消息中心',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/messagecenter/messageItem').default);
                                    cb(null, require('./routes/messagecenter/messageItem/Index').default);
                                });
                            }
                        }
                    ]
                },
                {
                    path: 'report/',
                    name: '报表管理',
                    breadcrumbName: '报表管理',
                    childRoutes: [
                        {
                            path: 'customer',
                            name: '客户信息',
                            breadcrumbName: '客户信息',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/report/customerReport').default);
                                    cb(null, require('./routes/report/customer/Index').default);
                                });
                            }
                        },
                        {
                            path: 'order',
                            name: '订单出货信息',
                            breadcrumbName: '订单出货信息',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/report/orderReport').default);
                                    cb(null, require('./routes/report/order/Index').default);
                                });
                            }
                        },
                        {
                            path: 'charge',
                            name: '费用明细',
                            breadcrumbName: '费用明细',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/report/orderChargeReport').default);
                                    cb(null, require('./routes/report/orderCharge/Index').default);
                                });
                            }
                        },
                        {
                            path: 'forex',
                            name: '收汇信息',
                            breadcrumbName: '收汇信息',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/report/forexReport').default);
                                    cb(null, require('./routes/report/forex/Index').default);
                                });
                            }
                        },
                        {
                            path: 'taxinv',
                            name: '退税融资信息',
                            breadcrumbName: '退税融资信息',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/report/taxInvReport').default);
                                    cb(null, require('./routes/report/taxInv/Index').default);
                                });
                            }
                        },
                        {
                            path: 'benefit',
                            name: '利润统计报表',
                            breadcrumbName: '利润统计报表',
                            getComponent(nextState, cb) {
                                require.ensure([], (require) => {
                                    registerModel(app, require('./models/report/orderbenefitReport').default);
                                    cb(null, require('./routes/report/orderBenefit/Index').default);
                                });
                            }
                        },
                    ]
                },
            ]
        },
        {
            path: '/login',
            name: '工作台',
            breadcrumbName: '工作台',
            getComponent(nextState, cb) {
                require.ensure([], (require) => {
                    registerModel(app, require('./models/auth/login').default)
                    cb(null, require('./routes/auth/common/Login').default);
                });
            }
        },
    ];
    return <Router history={history} routes={routes}/>;
}

export default RouterConfig;
